package com.qf.controller;

import com.qf.pojo.req.RotationImageReq;
import com.qf.pojo.resp.BaseResp;
import com.qf.service.RotationImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api("轮播图控制器")
@RestController
@RequestMapping("/rotationImage")
public class RotationImageController {
    @Autowired
    RotationImageService rotationImageService;
    @ApiOperation(value = "查询所有轮播图")
    @RequiresPermissions("RONTATINOIMAGE_FIND_ALL")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "当前页显示行数",required = true,dataType = "Integer"),
    })
    @PostMapping("/findAll")
    public BaseResp findAll(@RequestParam("page")Integer page,@RequestParam("size")Integer size){
        return rotationImageService.findAll(page,size);
    }
    @ApiOperation(value = "新增或修改轮播图")
    @RequiresPermissions("RONTATIONIMAGE_UPDATE_OR_SAVE")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rotationImageReq",value = "请求轮播图对象",required = true,dataType = "RotationImageReq")
    })
    @PostMapping("/updateOrSave")
    public BaseResp updateOrSave(@RequestBody RotationImageReq rotationImageReq){
        return rotationImageService.updateOrSave(rotationImageReq);
    }
    @ApiOperation(value = "删除轮播图")
    @RequiresPermissions("RONTATIONIMAGE_DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "map",value = "删除的轮播图id",required = true,dataType = "Map")
    })
    @PostMapping("/deleteById")
    public BaseResp deleteById(@RequestBody Map map){
        return rotationImageService.deleteById(Integer.valueOf(map.get("id").toString()));
    }
}
